<?php

namespace App\Services\Applet\Payment;

use App\Library\Payment\Wechat\WechatPayApi;
use Exception;
use Throwable;

/**
 *
 */
class WechatPayService extends BasePaymentService implements PaymentInterface
{
    /**
     * @var WechatPayApi $wechatPayApi
     */
    private WechatPayApi $wechatPayApi;


    /**
     * @throws Exception
     */
    public function __construct()
    {
        $this->wechatPayApi = loadLibrary('Payment\Wechat\WechatPayApi');
    }


    /**
     * app支付
     * @param string $subject 标题
     * @param string $orderNo 订单号
     * @param int $orderPrice 订单金额
     * @param array $batchOptional 其他参数
     * @return array
     */
    public function appPay(string $subject, string $orderNo, int $orderPrice, array $batchOptional = []): array
    {
        return $this->wechatPayApi->appPay($subject, $orderNo, $orderPrice, $batchOptional);
    }

    /**
     * 小程序支付
     * @return void
     */
    public function appletPay(string $subject, string $orderNo, int $orderPrice, array $batchOptional = []): array
    {
        return $this->wechatPayApi->appletPay($subject, $orderNo, $orderPrice, $batchOptional);
    }

    /**
     * 小程序支付
     * @return mixed
     */
    public function jsApiPay(string $subject, string $orderNo, int $orderPrice, array $batchOptional = []): array
    {
        return $this->wechatPayApi->jsApiPay($subject, $orderNo, $orderPrice, $batchOptional);
    }

    /**
     * 取消支付订单
     * @param string $orderNo
     * @return void
     */
    public function cancelPay(string $orderNo)
    {
        $this->wechatPayApi->cancel($orderNo);
    }

    /**
     * @return array
     * @throws Throwable
     * @var string $orderNo 订单号
     */
    public function query(string $orderNo): array
    {
        return $this->wechatPayApi->query($orderNo);
    }
}
